package cn.yeziji.forum.dao.impl;

import cn.yeziji.forum.common.ForumPageResult;
import cn.yeziji.forum.common.Paging;
import cn.yeziji.forum.converter.ShareLinkConverter;
import cn.yeziji.forum.dao.base.ForumShareLinkBaseDao;
import cn.yeziji.forum.dao.intf.ForumShareLinkDao;
import cn.yeziji.forum.dao.iquery.ShareLinkQuery;
import cn.yeziji.forum.dto.shareLink.ShareLinkDTO;
import cn.yeziji.forum.entity.ForumShareLinkEntity;
import cn.yeziji.forum.vo.shareLink.ShareLinkVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 分享链接逻辑实现层
 *
 * @author gzkemays
 * @since 2022/11/11 3:51 PM
 */
@Repository
public class ForumShareLinkDaoImpl extends ForumShareLinkBaseDao implements ForumShareLinkDao {
  @Override
  public void audit(String id) {
    ForumShareLinkEntity entity = selectById(id);
    entity.setDelete(!entity.getDelete());
    updateById(entity);
  }

  @Override
  public void submit(ShareLinkDTO dto) {
    ForumShareLinkEntity entity = dto.createEntity();
    save(entity);
  }

  @Override
  public ForumPageResult<ShareLinkVO> list(Paging paging) {
    List<ForumShareLinkEntity> forumShareLinkEntities =
        mapper.listEntity(ShareLinkQuery.findShareAuditLinkPagingQuery(paging));
    paging.total(mapper.count(ShareLinkQuery.findShareAuditLinkQuery()));
    return new ForumPageResult<>(
        ShareLinkConverter.INSTANCE.entitiesConvertToVOs(forumShareLinkEntities), paging);
  }
}
